package dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.stereotype.Repository;

import config.SqlConfig;


@Repository
public class DeviceDao {
	
	@Autowired
	JdbcTemplate jdbcTemplate;
	
	static Logger logger = Logger.getLogger(DeviceDao.class.getName());

	
	/**
	 * 根据设备序列号获取Id
	 * @param 
	 * @return
	 */
	public Integer getDeviceId(String deviceseq) {
		final Integer[] userId={null};
		Object[] params = new Object[]{ deviceseq };
		jdbcTemplate.query(SqlConfig.queryDeviceIdByseq, params,new RowCallbackHandler() {
			public void processRow(ResultSet rs) throws SQLException {
				userId[0]=rs.getInt("terminal_id");
			}
		});
		//Integer userId=jdbcTemplate.queryForObject(SqlConfig.queryUserIdByWxID, params, Integer.class);
		return userId[0];
	}


}